# Maintainer: Bruno Pagani <archange@archlinux.org>
# Contributor: Christoph Hoopmann <choopm at 0pointer.org>
# Contributor: Pascal E. <archlinux at hardfalcon dot net>
# Contributor: Andrej Gelenberg <andrej.gelenberg at udo dot edu>

pkgname=libnfc
pkgver=1.8.0
pkgrel=2
pkgdesc="Platform independent Near Field Communication (NFC) library"
arch=(loong64 x86_64)
url="http://nfc-tools.org/"
license=(LGPL3)
depends=(libusb-compat pcsclite)
makedepends=(cmake)
optdepends=('acsccid: acr122_pcsc support')
source=(https://github.com/nfc-tools/libnfc/releases/download/${pkgname}-${pkgver}/${pkgname}-${pkgver}.tar.bz2)
sha256sums=('6d9ad31c86408711f0a60f05b1933101c7497683c2e0d8917d1611a3feba3dd5')

prepare() {
  # Use uaccess 
  sed -i "s|MODE=\"0664\", GROUP=\"plugdev\"|TAG+=\"uaccess\"|g" ${pkgname}-${pkgver}/contrib/udev/93-pn53x.rules
  mv ${pkgname}-${pkgver}/contrib/udev/{93,70}-pn53x.rules
}

build() {
  cmake -B build -S ${pkgname}-${pkgver} \
    -DCMAKE_INSTALL_PREFIX=/usr \
    -DLIBNFC_DRIVER_PCSC=ON \
    -DLIBNFC_DRIVER_ACR122_PCSC=ON \
    -DLIBNFC_DRIVER_ACR122_USB=ON \
    -DLIBNFC_DRIVER_PN532_I2C=ON \
    -DLIBNFC_DRIVER_PN532_SPI=ON \
    -DLIBNFC_DRIVER_PN532_UART=ON \
    -DLIBNFC_DRIVER_PN53X_USB=ON \
    -Wno-dev
  make -C build
}

package() {
  make -C build DESTDIR="${pkgdir}" install
  cd ${pkgname}-${pkgver}
  install -Dm644 libnfc.conf.sample -t "${pkgdir}"/etc/nfc/
  install -Dm644 contrib/udev/70-pn53x.rules -t "${pkgdir}"/usr/lib/udev/rules.d/
  install -Dm644 contrib/linux/blacklist-libnfc.conf -t "${pkgdir}"/usr/lib/modprobe.d/
}
